<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list' || $_RQ['op']=='mlist'){	
	$params=array('type <>'=>4,'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['op']=='list'){
		$params['merchid']=0;
		$goodsurl='jy_weishop/goods.get_goods//nomerch=1';
	}elseif($_RQ['op']=='mlist' && !$_RQ['merchid']){
		$params['merchid >']=0;
	}
	$return['params']['toop']=$_RQ['op'];
	if(intval($_RQ['merchid'])){
		$params['merchid']=intval($_RQ['merchid']);
		$return['params']['merchid']=$_RQ['merchid'];
	}
	$params['onepluginname']='';
	$return['list']=pdo_getall('jy_weishop_goods',$params,array('id','title','image','merchid'));
	$params2=array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1);	
	if($_RQ['createtime']){
			$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
			$time_range=json_decode($time_range,true);
			$params2['createtime between']=array($time_range['tstart'],$time_range['tend']);
			$return['params']['createtime']=$time_range;
	}
	foreach($return['list'] as $k=>&$v){
		$merch=pdo_get('jy_merch_user',array('id'=>$v['merchid'],'uniacid'=>$_SESSION['uniacid']),array('id','merchname','logo','salecate'));
		$v['merchname']=$merch['merchname']?:'';
		$v['merchlogo']=$merch['logo'];
		$params2['goodsid']=$v['id'];
		$v['total']=pdo_getsum('jy_weishop_order_goods',$params2,'total');
		if(!$v['total']){
			unset($return['list'][$k]);
			continue;
		}
		$v['totalprice']=pdo_getsum('jy_weishop_order_goods',$params2,'total_price');
	}
	paixu($return['list'],'total','desc');
	foreach($return['list'] as $k=>&$v){
		$v['rank']=$k+1;
	}
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排行','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'image','title'=>'商品图片','type'=>'image'),			
			array('name'=>'total','title'=>'销售量','type'=>'string'),
			array('name'=>'totalprice','title'=>'销售额','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'createtime','width'=>15,'title'=>'下单时间','type'=>'time_range'),
		)
	);
	if($_RQ['op']=='mlist'){
		$htmls['search'][]=array('type'=>'choose','width'=>13,'title'=>'所属商户','name'=>'merchid','action'=>'jy_merch/get_merch/');
		$htmls['list']['list'][0]=array('name'=>'merchname','title'=>'所属商户','type'=>'string');
	}
	$return['htmls']=$htmls;
	exi($return);
}
